package com.wus.system.controller;

import com.wus.common.core.domain.base.Result;
import com.wus.common.log.annotation.Log;
import com.wus.common.log.enums.BusinessType;
import com.wus.system.request.SysDictTypeAddReq;
import com.wus.system.request.SysDictTypeDeleteReq;
import com.wus.system.request.SysDictTypeQueryReq;
import com.wus.system.request.SysDictTypeUpdateReq;
import com.wus.system.response.SysDictTypeResp;
import com.wus.system.service.ISysDictTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 字典类型控制类
 * @Author: wus
 * @Date: 2025/1/6 15:34
 */
@Tag(name = "字典类型管理")
@Validated
@RequiredArgsConstructor
@RequestMapping("/system/dict/type")
@RestController
public class SysDictTypeController {

    private final ISysDictTypeService dictTypeService;

    @Operation(summary = "分页查询字典类型")
    @PostMapping("/list")
    public Result<List<SysDictTypeResp>> list(@Validated @RequestBody SysDictTypeQueryReq req) {
        return Result.ok(dictTypeService.list(req));
    }

    @Operation(summary = "查询字典类型")
    @GetMapping("/{id}")
    public Result<SysDictTypeResp> getDetailById(@PathVariable("id") Long id) {
        return Result.ok(dictTypeService.getDetailById(id));
    }

    @Operation(summary = "新增字典类型")
    @Log(title = "字典类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public Result<Boolean> add(@Validated @RequestBody SysDictTypeAddReq req) {
        return Result.ok(dictTypeService.add(req));
    }

    @Operation(summary = "删除字典类型")
    @Log(title = "字典类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete")
    public Result<Boolean> delete(@Validated @RequestBody SysDictTypeDeleteReq req) {
        return Result.ok(dictTypeService.delete(req));
    }

    @Operation(summary = "修改字典类型")
    @Log(title = "字典类型", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public Result<Boolean> update(@Validated @RequestBody SysDictTypeUpdateReq req) {
        return Result.ok(dictTypeService.update(req));
    }
}
